[#include "/common/macro/header.ftl" /]
[@header title="日志管理" /]
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-tab layui-tab-brief">
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <form class="layui-form" action="" lay-filter="LAY-pla-system-log-list-filter-form">
                        <div style="margin-bottom: 10px;">
                            <div class="layui-form-item">
                                <div class="layui-input-inline">
                                    <input type="text" class="layui-input" placeholder="操作人/ip地址" name="keyword">
                                </div>
                                <div class="LAY-list-btns">
                                    <button class="layui-btn layui-btn-primary" lay-submit
                                            lay-filter="LAY-pla-system-log-list-filter-form-query"><i
                                            class="layui-icon">&#xe615;</i>查询
                                    </button>
                                </div>
                            </div>
                        </div>
                    </form>
                    <div class="LAY-list-btns" style="margin-bottom: 10px;">
                        <button class="layui-btn layui-btn-sm layui-btn-danger" data-events="clearAll">
                            <i class="layui-icon layui-icon-delete"></i>清除全部
                        </button>
                    </div>
                    <table id="LAY-system-log-table" lay-filter="LAY-system-log-table"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="LAY-system-log-table-bar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="view"><i
            class="layui-icon layui-icon-search"></i></a>
</script>

<script src="${base}/static/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '${base}/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'form'], function () {
        var $ = layui.$
                , admin = layui.admin
                , setter = layui.setter
                , response = setter.response
                , table = layui.table
                , form = layui.form;

        table.render({
            elem: '#LAY-system-log-table'
            , url: '${base}/admin/logs'
            , response: {
                statusCode: 20000 //成功的状态码，默认：0
            }
            , cellMinWidth: 80 //全局定义常规单元格的最小宽度
            , page: true
            , cols: [[
                {field: 'operator', title: '操作人', sort: true}
                , {field: 'operation', title: '操作', sort: true}
                , {
                    field: 'ip',
                    title: 'IP地址',
                    sort: true
                }, {
                    field: 'createDate',
                    title: '创建时间',
                    sort: true
                }, {
                    field: 'params',
                    title: '操作参数'
                }
            ]]
        });

        //事件处理
        var events = {
            clearAll: function (othis, type) {
                layer.confirm('确定要清除全部吗？', function (index) {
                    admin.req({
                        url: '${base}/admin/logs/all'
                        , type: 'delete'
                        , success: function (res) {
                            var statusCode = response.statusCode;
                            if (res[response.statusName] === statusCode.ok) {
                                layer.msg('清除成功', {
                                    icon: 1
                                });
                                table.reload('LAY-system-log-table'); //刷新表格
                            }
                        }
                    });
                    layer.close(index);
                });

            }
        };

        //监听工具条
        $('.LAY-list-btns .layui-btn').on('click', function () {
            var othis = $(this)
                    , thisEvent = othis.data('events')
                    , type = othis.data('type');
            events[thisEvent] && events[thisEvent].call(this, othis, type);
        });


        form.on('submit(LAY-pla-system-log-list-filter-form-query)', function (data) {
            table.reload('LAY-system-log-table', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                , where: data.field
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });


    });
</script>
</body>
</html>
